home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
1874.ZIP
/
T-TOOLS.ZIP
/
TOOLDOC.ASC
< prev
next >
Wrap
Text File
|
1989-12-20
|
60KB
|
1,333 lines
********************************************************************
* *
* Turbo Tools 1.0 *
* *
* for Borland's Turbo Pascal 4.0, 5.0, and 5.5 *
* *
* copyright 1989 *
* *
* Chuck Esterbrook *
* *
********************************************************************
YOU SHOULD READ ALL OF PART ONE BEFORE USING TURBO TOOLS.
DON'T FORGET TO REGISTER!
I. Introduction
II. unit Crt2
III. unit Input
IV. unit Keys
V. unit StrFuncs
********************************************************************
* *
* Turbo Tools 1.0 *
* *
* for Borland's Turbo Pascal 4.0, 5.0, and 5.5 *
* *
* copyright 1989 *
* *
* Chuck Esterbrook *
* *
********************************************************************
YOU SHOULD READ ALL OF PART ONE BEFORE USING TURBO TOOLS.
DON'T FORGET TO REGISTER!
I. Introduction
A. Documentation and printing
1) Documentation files
2) TOOLDOC.ASC arrangement
3) Printing files
B. Registration
1) What is shareware?
2) What you get for registering Turbo Tools
3) How to register
C. Disk files
1) Original disk
2) Installed
D. Installation
E. Using units
II. unit Crt2
A. Explanation
B. Initialization Code
C. Exit Code
D. Center
E. CanUseColor
F. Cursor/CursorState/CursorTypes
G. DelChar
H. Frame
I. GetKey/GetKeyUp
J. GlobalX/GlobalY
K. InsSpace
L. LowBeep
M. ScrWidth/ScrLength
N. VideoSeg
O. WriteLast
III. unit Input
A. Word of warning
B. Explanation
C. Initialization and Exit Code
D. Escaped
E. Minimum/Maximum integer range constants
F. Integer input routines
G. ReadStr
H. AllChars
IV. unit Keys
A. Explanation
B. Constant Identifiers
1) Single Code Special Keys
2) Extended Code Special Keys
C. Example
V. unit StrFuncs
A. Explanation
B. Initialization and Exit Code
C. CopyEnd
D. DelOccurs
E. LowCase
F. LowStr
G. PosOccur
H. Occurs
I. Shave
J. ShaveLead
K. ShaveTrail
L. UpStr
********************************************************************
* *
* Turbo Tools 1.0 *
* *
* for Borland's Turbo Pascal 4.0, 5.0, and 5.5 *
* *
* copyright 1989 *
* *
* Chuck Esterbrook *
* *
********************************************************************
YOU SHOULD READ ALL OF PART ONE BEFORE USING TURBO TOOLS.
DON'T FORGET TO REGISTER!
I. Introduction
A. Documentation and printing
1) Documentation files
There are two documentation files for Turbo Tools. The
first is TOOLINFO.ASC which is a quick list of all types,
variables, procedures, functions, units, compiler
directives, and files that make up Turbo Tools. You'll
definitely want to print this out since it will be a little
while until you remember all the extra commands at your
disposal and their parameters. This file will print in 3
pages.
The second file is TOOLDOC.ASC which is the entire
documentation for Turbo Tools. On printers that put 66
lines on a page, it will print in 23 pages. On printers
that put 60 lines on a page, it will print in 25. You can
view both these files by loading them into Turbo Pascal and
scrolling through them, although it is strongly recommended
that you print them out.
2) TOOLDOC.ASC arrangement
As you might have noticed, TOOLDOC.ASC is arranged in
outline format. This is because it was written with an
outliner/PIM program named GrandView. I wrote the
documentation with GrandView because I feel that the
outline format makes it easier to read and thumb through. I
hope you find it that way, also. The units are documented
in alphabetical order and the routines in each unit are
also listed and documented in alphabetical order. I suggest
that you simply read the documentation page by page,
instead of leafing through to different sections. The Crt2
unit, which is documented first, is probably the best unit
to start out with anyway.
3) Printing files
You can print the documentation files from DOS with
"COPY filename PRN", or you can load them into the Turbo
Pascal Editor and print them from there (CONTROL-K,
CONTROL-P).
B. Registration
1) What is shareware?
If you are already familiar with shareware and
registration fees you can skip this section and go to the
next one (Section 2).
Turbo Tools is a shareware product. Shareware software
can be distributed freely as long as it is distributed in
its whole entirety. You can find shareware on BBS's and in
catalogs that usually charge a small fee, such as $5 per
disk full of software. You might also be able to copy some
shareware from your friends. Once you have the shareware
you can try it out and if you like it and plan to use it
then you send payment for the software to the author.
Authors benefit by using the shareware method because there
is no advertising overhead as with commercial software.
Customers benefit because the authors pass these savings
onto them by offering a lower registration fee than what a
similar commercial product would cost. Customers also get
to try out the software before they "buy" it.
Why should you pay the registration fee when you could
keep using the program for free? Well, for one thing, if
you really like the product, then the author probably put a
lot of work into it. If his program is saving you time and
helping you work faster or do something that you weren't
doing before, then you owe him his money. And besides being
honorable, it's usually in *YOUR* best interests to
register, because many authors (including this one) offer
benefits to registered users that you'll definitely want.
2) What you get for registering Turbo Tools
The registration free for Turbo Tools is $10. In return
you get the complete source code for the entire system,
free unlimited technical support through the mail, notices
of future updates, and if I find or am alerted of a serious
bug in the system I'll rush you a letter describing how to
fix the source code. You'll also be registered for the
latest version of Turbo Tools. For example, if you are
registering version 1.0, but a version 2.0 has already been
released, then I'll simply send you version 2.0, even if
the registration price is higher.
The biggest reason you'll want to register Turbo Tools
is for the source code, and here's why:
First of all, the compiler directives for the units
can't be changed unless you have the source code. When you
get the source code you can set the directives to your own
preferences and recompile the units.
What happens if you want one of the routines in Turbo
Tools to work slightly different than how it does now? If
you don't have the source code you have to rewrite the
whole routine from scratch, and if you have no idea how it
works in the first place then you won't be rewriting
anything. If you have the source code, however, you can
examine the routine and make the modifications you want.
There's also the problem of TPU's. Every version of
Turbo Pascal uses a different format for TPU files. Turbo
Tools includes TPU's for Turbo Pascal 4.0, 5.0, and 5.5,
but if Borland releases a version 6.0 it will probably also
use a different TPU format. That would leave you out in the
cold. The only way to solve that problem is to have the
source code so you can recompile the units.
As you can see, a mere $10 gives you a lot of advantages
that you definitely could use.
3) How to register
To register I'll need your check for $10 made payable to
Charles Esterbrook and some necessary information that you
can write on a piece of paper, or if you have bad hand
writing, you can type it with the Turbo Pascal editor and
press CONTROL-K, CONTROL-P to print it. The information
I'll need follows:
(1) The version of Turbo Tools you are registering,
(2) Your version of Turbo Pascal.
(3) If you want the source code on floppy disks
(5 1/4"), micro disks (3 1/2") or if you have
both types of drives and it doesn't matter.
(4) And finally, your return address.
You can expect your new disk and registration ID within
two weeks. This is my address:
Chuck Esterbrook
Attn: Turbo Tools 1.0
4980 West 89th Terrace
Crown Point, IN
46307
To help me separate my business mail from my personal
mail please include the attention line, and for the sake of
decreasing the chances of it getting lost in the mail or
taking a very long time, please put the zip code on a
separate line by itself, far to the right. Thank you.
C. Disk files
1) Original disk
Turbo Tools comes with several files which are listed
here. If you list a directory and find that you didn't get
all of the files for Turbo Tools you can send me $5 (for
the disk and shipping and handling) and I will send you the
unregistered version of Turbo Tools. Or you can simply send
$10 and I'll just send you the registered version of Turbo
Tools. See Part I.B.2. for information concerning
registration. My address is located in Part I.B.3.
README.EXE instructions for getting started with
Turbo Tools
INSTALL.BAT installation batch file for Turbo Tools
CONTINUE.ASC this file is displayed by INSTALL.BAT
after Turbo Tools has been installed
TOOLINFO.ASC quick information about Turbo Tools (for
printing)
TOOLDOC.ASC complete documentation for Turbo Tools
(what you're reading right now)
CRT2DEMO.PAS demonstration program for the Crt2 and
Keys unit
*.40 TPU files for Turbo Pascal 4.0
*.50 TPU files for Turbo Pascal 5.0
*.55 TPU files for Turbo Pascal 5.5
2) Installed
The installation program will install the following
files to your Turbo Pascal directory (or directories).
TOOLINFO.ASC
TOOLDOC.ASC
CRT2DEMO.PAS
CRT2.TPU
INPUT.TPU
STRFUNCS.TPU
KEYS.TPU
D. Installation
There is an installation program provided on disk to copy
and rename the appropriate Turbo Tools file to your Turbo
Pascal directory(ies). For instructions, change to the drive
with the Turbo Tools disk and enter README at the DOS prompt.
E. Using units
Turbo Tools 1.0 consists of four units: Crt2, Input,
StrFuncs, and Keys. These units can be used just like the
Turbo Pascal units Crt, Dos, Printer, and Graph. Simply
specify the name of the unit you want access to in the USES
clause:
program Example;
uses
crt, { TURBO PASCAL SCREEN LIBRARY }
Crt2, { TURBO TOOLS SCR. LIB. TO SUPPLEMENT Crt }
StrFuncs; { TURBO TOOLS STRING LIBRARY }
II. unit Crt2
A. Explanation
Crt2 acts as an extension to Turbo Pascal's Crt unit. All
the routines and variables are concerned with text screens,
sound, and single key input. All the routines work in any text
mode you set with Crt's TextMode procedure and any window you
create with Crt's Window procedure. To make Crt2 available to
your programs insert Crt2 in the USES clause.
Example:
uses
crt,
Crt2;
You should be familiar with the Crt unit before you learn
how to use Crt2. Especially the TextMode and Window procedures
which are referred to in this part of the manual.
B. Initialization Code
Every unit can have initialization code, although it
doesn't have to. Initialization code executes before the
program that uses it does. See the Turbo Pascal Reference
Manual for more specifics.
Crt2's initialization code does several things. It sets up
the exit code (see next heading), initializes the variable's
ScrLength, ScrWidth, and VideoSeg, and it sets the cursor to
normal height using the procedure Cursor declared in this
unit.
C. Exit Code
Every unit can have exit code, although it doesn't have to.
Exit code executes after the program that uses it terminates.
See the Turbo Pascal Reference Manual for more specifics.
Crt2 has exit code and it does only one thing: makes a call
to the Cursor procedure to set the cursor to normal height
(the same as the initialization code does).
D. Center
1) DECLARATION: procedure Center(st : string) : string;
2) PURPOSE: For centering text on the screen.
3) EXPLANATION: Center returns the string it is given with
leading spaces inserted so that when printed in the current
window it will be centered.
4) EXAMPLE:
uses crt,Crt2;
begin
window(10,5,70,20);
writeln(Center('This is centered.'));
while readkey=#0 do; { WAIT FOR A KEY TO BE PRESSED }
end.
E. CanUseColor
1) DECLARATION: function CanUseColor : boolean;
2) PURPOSE: Returns true if color is available, false if not.
3) EXPLANATION: CanUseColor returns true if the video adapter
has color capabilities. It does not detect monochrome
(black and white) monitors. A user could have an EGA color
card, but a EGA monochrome display. In this case, the
different colors would just appear as different shades of
gray.
4) EXAMPLE: This example directly sets the current text colors
instead of using the Crt routines TextColor and
TextBackground. For an explanation of TextAttr, look it up
in the index of your Turbo Pascal Reference Manual.
uses crt,Crt2
begin
if CanUseColor then
textattr := lightgray + blue*16
else
textattr := lightgray + black*16;
{ IF COLOR THEN LIGHTGRAY ON BLUE,
ELSE LIGHTGRAY ON BLACK }
F. Cursor/CursorState/CursorTypes
1) DECLARATION:
type CursorTypes = (CursorOff,NormalCursor,
HalfCursor, FullCursor);
var CursorState : CursorTypes;
procedure Cursor(Mask : CursorTypes);
2) PURPOSE: The Cursor procedure is used to set the cursor
appearance. The CursorState variable is used to hold the
current appearance of the cursor. The CursorTypes type is
used for declaring CursorState and Cursor's single
parameter.
3) EXPLANATION: There are four different ways you can call the
procedure Cursor:
Cursor(CursorOff);
Cursor(NormalCursor);
Cursor(HalfCursor);
Cursor(FullCursor);
The first call hides the cursor so that it can't be seen.
The second sets the cursor to normal height (the same as
the cursor in Turbo Pascal's editor). The third sets the
cursor to half height like the cursor you normally see in a
word processor when insert mode is on. Full cursor sets the
cursor to full block height.
The variable CursorState is set by the Cursor procedure
to hold the current appearance of the cursor. You can check
this variable with If statements and Case clauses.
The type CursorTypes is used to declare the variable
CursorState and Cursor's single parameter. You can define
your own variables of type CursorTypes and save the value
of CursorState for later restoration of the cursor (see
example).
4) INIT CODE: The initialization code of Crt2 sets the cursor
to normal height using this procedure.
5) EXIT CODE: The exit code does the same. You don't have to
worry about making sure the cursor is visible or normal
before terminating your program, because the unit will take
care of that for you.
6) EXAMPLE:
uses crt,Crt2;
var
x,y : byte;
FileName : string[13];
procedure WriteStatusLine;
var
SaveCursor : CursorTypes;
SaveX,SaveY : byte;
begin
SaveCursor := CursorState;
{SAVE CURRENT STATE OF CURSOR}
SaveX := wherex; SaveY := wherey;
Cursor(CursorOff);
gotoxy(1,2); write(x,' ',y,' ',FileName);
gotoxy(SaveX,SaveY);
Cursor(SaveCursor);
{ RESTORE CURSOR TO PREVIOUS STATE }
end; { WriteStatusLine }
begin
FileName := 'NONAME.PAS';
StatusLine;
end.
G. DelChar
1) DECLARATION: procedure DelChar(Count : byte);
2) PURPOSE: Deletes one or more characters from the current
line.
3) EXPLANATION: DelChar is the column complement to Crt's
DelLine procedure. Use the count parameter to specify how
many characters to delete. The procedure affects only the
line the cursor is positioned on, works fine in windows,
and does not affect the cursor position.
4) SEE ALSO: InsSpace
5) EXAMPLE:
uses crt,Crt2;
begin
clrscr;
writeln('Delete the first word');
while readkey=#0 do; { WAIT FOR KEY A TO BE PRESSED }
gotoxy(1,1);
DelChar(7); {the first word}
while readkey=#0 do;
end.
H. Frame
1) DECLARATION:
procedure Frame(x1,y1,x2,y2,Top,Bottom,Left,Right : byte);
2) PURPOSE: Draws a frame on the screen.
3) EXPLANATION: The Frame procedure uses special ASCII
characters to draw frames just like the ones found in the
Turbo Pascal Environment surrounding popup windows and
menus. x1,y1 specifies the upper left hand corner's
coordinates and x2,y2 the lower right. Each side of the
frame can be drawn with a single or double line. Specify
either 1 or 2 for the last four parameters to control this.
Frame does not affect the cursor position or appearance in
any way.
4) EXAMPLE:
uses crt,Crt2;
begin
clrscr;
Frame(1,1,80,25, 1,1,1,1); {ALL SIDE ARE SINGLE LINED}
Frame(3,3,40,10, 2,2,1,1); {TOP AND BOTTOM DOUBLE}
Frame(45,3,75,12, 2,2,2,2);{ALL SIDES DOUBLE}
Frame(3,13,78,24, 2,1,2,1);{TOP AND LEFT DOUBLE}
while readkey=#0 do; { WAIT UNTIL A KEY IS PRESSED }
end.
I. GetKey/GetKeyUp
1) DECLARATION:
type SetOfChar = set of char;
function GetKey(Acceptable : SetOfChar) : char;
function GetKeyUp(Acceptable : SetOfChar) : char;
2) PURPOSE: Filtered single key input.
3) EXPLANATION: GetKey works the same as Crt's ReadKey
function except that GetKey accepts only the input you want
it to. For instance, if you gave GetKey the set ['0'..'9']
it would only return one of those values. If the user
pressed A, GetKey would ignore it and wait for another key.
GetKeyUp is the same as GetKey except that it converts
input into upper case letters before it checks to see if it
is acceptable.
4) EXAMPLE: Note that #27 is the ASCII code for the ESCAPE
key.
uses crt,Crt2;
procedure Choice1; begin end;
procedure Choice2; begin end;
procedure Choice3; begin end;
procedure Choice4; begin end;
begin
while true do begin { REPEAT INDEFINITELY }
writeln('MENU');
{ PUT MENU HERE }
case GetKey(['1'..'4',#27]) of {A NUMBER OR ESCAPE}
'1' : Choice1;
'2' : Choice2;
'3' : Choice3;
'4' : Choice4;
#27 : halt;
end; { case }
end; { while }
end.
J. GlobalX/GlobalY
1) DECLARATION: function GlobalX : byte;
function GlobalY : byte;
2) PURPOSE: Returns the coordinates of the cursor position
relative to the screen, not the current window.
3) EXPLANATION: Turbo Pascal's Crt unit provides the functions
WhereX and WhereY for the cursor position in the current
window. GlobalX and GlobalY return the cursor position for
the screen regardless of where and how big the current
window is. GlobalX and GlobalY were intended for use with
direct video writing which is explained with the variable
VideoSeg.
4) SEE ALSO: var VideoSeg
5) EXAMPLE:
uses crt,Crt2;
begin
window(10,5,40,20);
write('Window 10,5 and 40,20');
write('WhereX,WhereY = ',wherex,',',wherey);
write('GlobalX,GlobalY = ',GlobalX,',',GlobalY);
while readkey=#0 do; { WAIT FOR A KEY TO BE PRESSED }
end.
K. InsSpace
1) DECLARATION: procedure InsSpace(Count : byte);
2) PURPOSE: Inserts one or more spaces into the current line.
3) EXPLANATION: InsSpace is the column complement to Crt's
InsLine procedure. Use the Count parameter to specify how
many spaces to insert. The procedure affects only the line
the cursor is positioned on, works fine in windows, and
does not affect the cursor position.
4) SEE ALSO: DelChar
5) EXAMPLE:
uses crt,Crt2;
begin
clrscr;
writeln('the first word');
while readkey=#0 do; { WAIT FOR KEY TO BE PRESSED }
gotoxy(1,1);
{the first word}
InsSpace(7);
{ the first word}
while readkey=#0 do;
write('Insert');
while readkey=#0 do;
end.
L. LowBeep
1) DECLARATION: procedure LowBeep;
2) PURPOSE: Emits a low pitched beep from the speaker.
3) EXPLANATION: LowBeep is the simplest routine in this unit.
It's purpose is to replace write(^G) which produces a very
high pitched annoying tone.
4) EXAMPLE:
uses crt,Crt2;
begin
write('Hurts my ears!',^G);
while readkey=#0 do; { WAIT FOR A KEY TO BE PRESSED }
write('Much better!'); LowBeep;
while readkey=#0 do;
end.
M. ScrWidth/ScrLength
1) DECLARATION: var ScrWidth,
ScrLength : byte;
2) PURPOSE: Contains the current width and length of the text
screen.
3) EXPLANATION: ScrWidth is the width of the screen in
columns. ScrLength is the length of the screen in rows.
ScrWidth will always be either 40 or 80. ScrLength will
always be either 25, 43, or 50. The really useful one out
of this pair is ScrLength since the Crt variable LastMode
won't give you specific enough information to tell you the
difference between EGA 43 line and VGA 50 line text modes.
Whenever you make a call to Crt's TextMode procedure, Crt2
will update the values of these two variables.
4) EXAMPLE:
uses crt,Crt2;
begin
gotoxy(1,ScrLength);
write('Press any key to continue...');
while readkey=#0 do;
end.
N. VideoSeg
1) DECLARATION: var VideoSeg : word;
2) PURPOSE: Holds the segment address of the video buffer.
3) EXPLANATION:
Before reading this section it would be to your
advantage to look up the varaibles TextAttr and Mem in your
Turbo Pascal Manual's Index and read about them.
The contents of the screen are stored in a buffer that
is located in between 640K and the 1MB mark. Using Turbo
Pascal's Mem and MemW array, you can directly set the
contents to change the screen. It is a tedious method, but
it provides much faster output that Write. It is usually
used in only loops. The reason it is faster is because the
cursor position is not changed and the boundaries of the
current window are taken into consideration. One problem
with this method is that the video buffer's location
differs depending on the video adapter. This is solved with
the VideoSeg variable which is set by Crt2's intialization
code to the correct location.
The video buffer in text mode consists of bytes
dedicated to characters and text attributes. For
information about the format of a text attribute look up
the explanation of TextAttr in the Turbo Pascal Reference
Manual (see the index). The first byte of the buffer is the
ASCII code of the first character on the screen. The byte
after that is the text attribute of that character. In
other words, it looks something like this:
column: 1 |2 |3 |4 |5 |6 |7 |
holds: CA|CA|CA|CA|CA|CA|CA|
Every C and A represents one byte of memory dedicated to
an ASCII code or text attribute, respectively. To access
one of the C's in this array-type structure use this
format:
mem[VideoSeg:2*(y*ScrWidth + x)]
To access an A (text attribute) add one to the offset:
mem[VideoSeg:2*(y*ScrWidth + x) + 1]
Since Mem is a variable you can assign a value to it
(direct write) or assign it to a variable or use it in an
expression (direct read). VideoSeg and ScrLength are both
Crt2 variables. The x,y coordinates (which you fill in) are
different than the kind you would use with GotoXY or Frame.
First of all, the upper left hand corner is not 1,1; it's
0,0. Also, the coordinates are not relative to the current
window. To access an attribute simply add 1 to x. Remember
that you can write to any screen location regardless of
where the cursor is, and after the write the cursor
position is not changed.
4) EXAMPLES:
TO WRITE A CHARACTER AT POSITION X,Y
mem[VideoSeg:2*(y*ScrLength + x)] := ord('A');
TO WRITE AN ATTRIBUTE AT POSITON X,Y
mem[VideoSeg:2*(y*ScrLength + x) + 1]
:= lightgray + blue*16;
TO WRITE BOTH A CHARACTER AND ATTRIBUTE (NOTE THE w)
memw[VideoSeg:2*(y*ScrLength + x)]
:= ord('A') + (lightgray + blue*16)*256;
TO RETRIEVE A CHARACTER FROM A SCREEN POSITION:
var c : char;
c := chr(mem[VideoSeg:2*(y*ScrLength + x)]);
TO RETRIEVE AN ATTRIBUTE FROM A SCREEN POSITON:
var a : byte;
a := mem[VideoSeg:2*(y*ScrLength + x) + 1];
TO WRITE AN ATTRIBUTE AT THE CURRENT CURSOR POSITION:
mem[VideoSeg:2*((GlobalY-1)*ScrWidth + GlobalX)]
:= ord('A');
O. WriteLast
1) DECLARATION: procedure WriteLast(ch : char);
2) PURPOSE: Write a character in the lower right hand corner
without scrolling the window.
3) EXPLANATION: Occasionally you may need to put a character
in the lower right hand corner of the screen (or current
window) but a Write at that position will always make the
screen scroll up. If this is undesired use WriteLast. It
will put the given character in the corner without any
scrolling effect and the cursor position will not change.
WriteLast uses the current text colors to write the
character the same as Write or Writeln.
4) EXAMPLE:
uses crt,Crt2;
begin
if CanUseColor then textmode(co80);
clrscr;
writeln('You can''t see this because it scrolls ',
'off!');
gotoxy(25,80); write(#219);
while readkey=#0 do; { WAIT FOR A KEY TO BE PRESSED }
clrscr;
writeln('This stays on the screen!');
WriteLast(#219);
while readkey=#0 do;
end.
III. unit Input
A. Word of warning
It will be much easier for you if you read all of Part III
BEFORE using the Input unit. Many of the items in this unit
are closely intertwined and it will be to your benefit to read
about all of them before putting anything to work.
B. Explanation
Turbo Pascal provides Readln for keyboard input, but most
programmers find it very unpractical. The unit Input consists
of bullet proof, flexible input routines for all integer types
and strings. All routines are functions, so you must assign
the function to a variable, or use it in an IF or CASE
statement. All routines begin with "Read" and continue with
the exact name of the data type that is going to be read (for
example ReadLongInt). The only exception to the naming
convention is ReadStr which is for string input. The unit also
contains constants such as MinByte and MaxWord so you don't
have to memorize the ranges of the different integer types.
These constants can be used with the integer input routines.
NOTE: The unit Crt2 also contains two input routines:
GetKey and GetKeyUp. See Part II.
C. Initialization and Exit Code
Input has no initialization or exit code.
D. Escaped
1) DECLARATION: var Escaped : boolean;
2) PURPOSE: Equals TRUE if the user escaped from the last
input routine.
3) EXPLANATION: This variable is set to TRUE if the user
pressed an escape key to get out of an input routine
instead of pressing ENTER. And of course if the user
pressed ENTER, then Escaped is set to false. Note that what
constitutes an escape key is determined by the programmer.
Every input routine in this unit allows the programmer to
define two sets of escape keys. The first set is for normal
keys such as ESCAPE that send only one ASCII code to the
computer. The second set is for specifying the extended
keys that send two ASCII codes to the computer (an ASCII
code of zero to signify an extended code and then a second
ASCII code which tells the program what key was pressed).
Examples of extended codes are F1, HOME, and LEFT ARROW.
Look up ReadKey in the Turbo Pascal Reference Manual for
more information. If you do not want the user to be able to
exit the input routine then leave the two sets empty (
[],[] ). The other sections will have more information.
4) EXAMPLE: Note that #27 is the ASCII code for the ESCAPE
key.
uses
Input;
var
Name : string;
begin
write('Enter your name: ');
Name := ReadStr(25,AllChars,[#27],[]);
if Escaped then begin
writeln('PROGRAM TERMINATED BY USER.');
halt;
end; { if }
writeln;
writeln('Hello, ',Name);
end.
E. Minimum/Maximum integer range constants
1) DECLARATION:
const
MinShortInt = -128;
MaxShortInt = 127;
MinByte = 0;
MaxByte = 255;
MinInt = -32768;
{ MaxInt = 32767; }
MinWord = 0;
MaxWord = 65535;
MinLongInt = -2147483468;
{ MaxLongInt = 2147483467; }
2) PURPOSE: Saves the programmer from having to memorize the
ranges of the different integer types.
3) EXPLANATION: Turbo Pascal has to predefined constants,
MaxInt and MaxLongInt, that are equal to the maximum ranges
of the Integer and LongInt types. This was a good idea,
except that someone at Borland forgot about the minimum
ranges as well as the other integer types.
4) EXAMPLE: Note that #27 is the ASCII code for the ESCAPE
key.
uses
crt,
Input;
var
EndOfLoop,
s : word;
begin
clrscr;
while true do begin
writeln('Enter a number greater than 100.');
writeln('Or press ESCAPE to quit.');
EndOfLoop := ReadWord(101,MaxWord,0,5,[#27],[]);
writeln;
writeln;
if Escaped then halt;
for s := 1 to EndOfLoop do begin
sound(s);
delay(3);
end; { for }
nosound;
end; { while }
end.
F. Integer input routines
1) DECLARATION:
type SetOfChar = set of char;
function ReadByte(Min,Max,Init : shorting; Field : byte;
EscapeBy,ExtEscape : SetOfChar) : byte;
ReadShortInt
ReadByte
ReadInteger
ReadWord
ReadLongInt
All integer input routines are defined with exactly the
same parameters.
2) PURPOSE: Replacement input routines for Readln.
3) EXPLANATION:
The integer input routines offer you more features and
are more sound proof than Turbo Pascal's Readln. Each one
works exactly the same except that it returns a different
integer type. None of the routines allow the user to type
anything but digits (0..9) and a negative sign. Unlike
Readln, the input routines won't allow users to enter
things line '-1-3' or 'a' which would cause runtime errors.
The Min and Max parameters let you set a range of values
that the user can enter. If he enters something outside the
range and presses ENTER the Crt2 LowBeep procedure will be
called and the routine will wait for more input. If you
want the user to be able to enter any number that will fit
in an integer type use 0,0. The integer range constants are
also at your disposal.
The Init parameter is the initial value that you want
the input field to be initialized with. If there is no
specific value you want, then just specify zero.
The Field parameter tells the input routine how many
characters wide the input field is to be. The length of the
number in digits will be restricted to the field length.
Make sure you give the field enough columns so that the Min
and Max values can be entered. Don't forget that the
negative sign requires a space.
EscapeBy is a set of characters such as [#27],
['A'..'Z'], and ['A'..'D','Q']. If the user presses a key
that is found in this set, then the input routine will
stop. It will return the value of Init and the variable
Escaped will be set to True. If you don't want the user to
be able to escape then pass [], which is an empty set.
EscapeExt is another set of characters for special keys
that first return a ASCII code zero and then another ASCII
code that represents the key. This set is in case you
wanted the user to be able to exit with F1 or DELETE, or
some other key that uses an extended code.
When an integer input routine is called the field will
be cleared and initialized with the value of Init. The
routine will then wait for input. Numbers are entered just
like a calculator, except that a negative sign must be
entered first. BACKSPACE can be used for corrections. If
the user presses ENTER, the function checks to see if the
number is in range. If not, the speaker beeps and the
routine waits for corrections. If so, the function sets the
variable Escaped to False and returns the number. Whether
the user presses ENTER or an escape key the cursor will NOT
go to the next line, like in Readln. It will stay at the
end of the field. Make sure that you don't make the field
length longer than the space left on the current line or
there will be problems.
For defining the EscapeBy and EscapeExt character sets,
you will probably want to use the unit Keys. See part IV.
4) SEE ALSO: Part IV. Keys
5) EXAMPLE:
uses
dos,
Input;
var
Month,Day,Year,DayOfWeek : word;
Age : byte;
begin
getdate(Month,Day,Year,DayOfWeek);
while true do begin
write('Enter your age, or ESCAPE to quit: ');
Age := ReadByte(0,120,0,2,[#27],[]);
writeln;
if Escaped then halt;
writeln('In the year 2000 you will be ',
2000-Year + Age,' years old.');
writeln('In the year 2020 you will be ',
2020-Year + Age,' years old.');
end; { while }
end.
G. ReadStr
1) DECLARATION:
function ReadStr(MaxLen : byte; Acceptable,
EscapeBy,ExtEscape : SetOfChar) : string;
2) PURPOSE: Replacement input routine for Readln.
3) EXPLANATION:
The ReadStr input routine offers more features and is
more sound proof than Turbo Pascal's Readln.
The MaxLen parameter specifies how many characters long
the user's input can be. String input can span over more
than one line, unlike the integer input routines. If the
user reaches the end of his available length and continues
to type on the keyboard the cursor will simple stay put.
The Acceptable parameter works the same as GetKey and
GetKeyUp's Acceptable parameter (in the Crt2 unit).
Acceptable is a set of characters such as
['A'..'Z','a'..'z'] which will be the only characters that
are allowed to be typed by the user. If a character is
received by ReadStr that is not found in Acceptable it will
be ignored. You can use the constant AllChars to let the
user enter anything.
EscapeBy and ExtEscape work exactly the same as with the
integer input routines.
EscapeBy is a set of characters such as [#27],
['A'..'Z'], and ['A'..'D','Q']. If the user presses a key
that is found in this set, then the input routine will
stop. It will return an empty string and the variable
Escaped will be set to True. If you don't want the user to
be able to escape then pass [], which is an empty set.
EscapeExt is another set of characters for special keys
that first return ASCII code zero and then another ASCII
code that represents the key pressed. This set is in case
you wanted the user to be able to exit with F1 or DELETE,
or some other key that uses an extended code.
ReadStr let's the user corret errors with BACKSPACE the
same as Readln. Note that because Turbo Pascal does not
allow strings to be used with Case clauses, ReadStr cannot
be used there either (since it returns a string). However,
the function can be used in If statements.
4) SEE ALSO: const AllChars (next letter)
5) EXAMPLE:
uses Input;
var Name : string[15];
begin
writeln('What is your name?');
Name := ReadStr(15,['A'..'Z','a'..'z'],[],[]);
writeln;
writeln('Hello, ',Name);
end.
H. AllChars
1) DECLARATION: const AllChars : set of char = [#32..#254];
2) PURPOSE: For use with ReadStr.
3) EXPLANATION: Many times when using ReadStr you will want to
let the user enter any character. In this case pass
AllChars for the ReadStr parameter, Acceptable.
4) EXAMPLE:
This example program also demonstrates that you don't have
to assign an input function a variable. You can use the
function anywhere its data type is expected, including if
and case statements, Writelns, and procedure and function
parameters.
program Typewriter;
uses
printer,
Input;
begin
writeln('Press ESCAPE to quit. Anything else is');
writeln('sent to the printer.');
while true do begin
writeln(lst,ReadStr(40,AllChars,[#27],[]));
writeln;
if Escaped then begin
writeln;
halt;
end;
end; { while }
end.
IV. unit Keys
A. Explanation
The unit Keys consists of 123 constants which represent
most of the special keys that you would want to recognize from
the keyboard. Examples are the arrow keys, the function keys,
and CONTROL and ALTERNATE shift combinations. Instead of
memorizing these ASCII codes or looking them up in a table you
can simply use the constants defined in Keys.
Note that most of the special keys are extended codes: the
first call to ReadKey will return a #0, and a second call will
return another ASCII code that identifies the input. See
ReadKey in the Turbo Pascal Reference Manual for more
information on getting extended codes.
Note that the F11 and F12 keys and there complements are
only applicable to the IBM PS/2 keyboards and compatibles.
These are also know as 101-keyboards and extended keyboards.
The Ctr key is the middle key on the numeric keypad labeled 5.
It DOES return an extended keyboard code when the keyboard
isn't in numerics lock despite what most people believe. The
constant _Extended is the first ASCII code returned by
extended keys (#0).
B. Constant Identifiers
1) Single Code Special Keys
_Backspace _Enter _Escape _Tab _Extended
2) Extended Code Special Keys
_ShiftTab
_Up _CtrlUp _AltUp
_Down _CtrlDown _AltDown
_Left _CtrlLeft _AltLeft
_Right
_Home
_End
_PageUp
_PageDown
_Ins
_Del
_Ctr
_F1.._F12
_ShiftF1.._ShiftF12
_CtrlF1.._CtrlF12
_AltF1.._AltF12
_AltA.._AltZ
_Alt1.._Alt0
C. Example
uses crt,Keys;
begin
case readkey of
_Extended : case readkey of
_Up : ;
_Down : ;
_Left : ;
_Right : ;
end; { case }
_Enter : ;
_Escape : ;
#32..#254 : ;
end; { case }
end.
V. unit StrFuncs
A. Explanation
StrFuncs contains 10 extra string functions to supplement
those included with Turbo Pascal. The examples for this unit
are not complete programs. They are listings of different ways
to call a particular function and what the function would
return. Since these functions are very easy to understand, the
normal EXPLANATION section that usually accompanies a routine
has been cut out. All explaining is done in the PURPOSE
section.
B. Initialization and Exit Code
StrFuncs has no initialization or exit code.
C. CopyEnd
1) DECLARATION:
function CopyEnd(st : string; x : byte) : string;
2) PURPOSE: Returns the last x bytes of the string st.
3) EXAMPLES:
CopyEnd('StrFuncs',5) = 'Funcs'
CopyEnd('Hello',1) = 'o'
CopyEnd(st,0) = ''
CopyEnd('Turbo Tools',100) = 'Turbo Tools'
D. DelOccurs
1) DECLARATION: function DelOccurs(Find,Target : string;
x : byte) : string;
2) PURPOSE: Returns Target with the first x occurrences of
Find deleted. If you want all occurrences of Find deleted
specify 255 for x.
3) EXAMPLES:
DelOccurs('x','xyz',1) = 'yz'
DelOccurs('x','xyz',2) = 'yz'
DelOccurs('turbo','hello',1) = 'hello'
DelOccurs('turbo','turbo',1) = ''
DelOccurs('','turbo',1) = 'turbo'
E. LowCase
1) DECLARATION: function LowCase(ch : char) : char;
2) PURPOSE: Returns ch as a lower case character. A
non-alphabetic character or lower case letter is returned
as is. This function is a complement to Turbo Pascal's
UpCase function which converts characters to upper case.
3) EXAMPLES:
LowCase('M') = 'm'
LowCase('x') = 'x'
LowCase('1') = '1'
F. LowStr
1) DECLARATION: function LowStr(st : string) : string;
2) PURPOSE: Returns st with all upper case characters
converted to lower case. Lower case and non-alphabetic
characters are left alone.
3) SEE ALSO: UpStr
4) EXAMPLES:
LowStr('HELLO') = 'hello'
LowStr('ps/2') = 'ps/2'
LowStr('') = ''
LowStr(' ') = ' '
G. PosOccur
1) DELCARATION:
function PosOccur(Find,Target : string; n : byte) : byte;
2) PURPOSE: Returns the position of the n'th occurrence of
Find in Target. This function is a complement to Turbo
Pascal's Pos function which returns the position of the
first occurrence of a string in another string. If there
are not n occurrences of Find in Target then a zero is
returned.
3) EXAMPLES:
PosOccur('x','x x x',2) = 3
PosOccur('t','What time?',1) = 4
PosOccur('t','What time?',2) = 6
PosOccur('t','What time?',3) = 0
PosOccur('t','What time?',0) = 0
H. Occurs
1) DECLARATION: function Occurs(Find,Target : string) : byte;
2) PURPOSE: Returns the number of times Find occurs is Target.
3) EXAMPLES:
Occurs('x','x x x') = 3
Occurs('t','What time?') = 2
Occurs('x','y y y') = 0
Occurs('','anything') = 0
Occurs('into nothing','') = 0
I. Shave
1) DECLARATION: function Shave(st : string) : string;
2) PURPOSE: Returns st with all leading and trailing spaces
deleted. The ends are "shaved" off.
3) SEE ALSO: function ShaveLead
function ShaveTrail
4) EXAMPLES:
Shave(' now ') = 'now'
Shave(' abc') = 'abc'
Shave('more examples ') = 'more examples'
Shave(' ') = ''
Shave('') = ''
J. ShaveLead
1) DECLARATION: function ShaveLead(st : string) : string;
2) PURPOSE: Returns st with all leading spaces deleted.
Trailing spaces are left untouched.
3) SEE ALSO: function Shave
function ShaveTrail
4) EXAMPLES:
Shave(' now ') = 'now '
Shave(' abc') = 'abc'
Shave('more examples ') = 'more examples '
Shave(' ') = ''
Shave('') = ''
K. ShaveTrail
1) DELCARATION: function ShaveTrail(st : string) : string;
2) PURPOSE: Returns st with all trailing spaces deleted.
Leading spaces are left untouched.
3) SEE ALSO: function Shave
function ShaveLead
4) EXAMPLES:
Shave(' now ') = ' now'
Shave(' abc') = ' abc'
Shave('more examples ') = 'more examples'
Shave(' ') = ''
Shave('') = ''
L. UpStr
1) DECLARATION: function UpStr(st : string) : string;
2) PURPOSE: Returns st with all lower case letters converted
to upper case.
3) SEE ALSO: LowStr
4) EXAMPLES:
LowStr('HELLO') = 'HELLO'
LowStr('ps/2') = 'PS/2'
LowStr('') = ''
LowStr(' ') = ' '
{----------------------------------------------------------------------------}
{ END OF TOOLINFO.ASC FOR TURBO TOOLS 1.0 (C) 1989 BY CHUCK ESTERBROOK }
{----------------------------------------------------------------------------}